package operation;

import book.Book;
import book.BookList;

/**
 * @program: 11.22
 * @description:
 * @author: 李鑫月
 * @create: 2021-11-22 21:19
 **/
public class DelOperation implements IOperation{
    public void work(BookList bookList){
        System.out.println("删除图书");
        System.out.println("请输入你所要删除的图书：");
        String name=scanner.nextLine();
        int size=bookList.getUsedsize();
        int i = 0;
        for (; i <size ; i++) {
            Book book=bookList.getposbook(i);
            if (book.getName().equals(name)){
                break;
            }
        }
        if (i<size){
            for (int j =i; j < size-1; j++) {
                Book book=bookList.getposbook(j+1);
                bookList.setBook(book,i);
            }
          Book book= bookList.getposbook(size);
            book=null;
            bookList.setUsedsize(size-1);
            System.out.println("删除成功");

        }
        else {
            System.out.println("未找到您要删除的图书");
        }
    }
}
